<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="小程序," />





  <link rel="alternate" href="/atom.xml" title="尛孟的博客" type="application/atom+xml" />






<meta name="description" content="audio 音频   1234567&amp;lt;audio poster=&quot;&amp;#123;&amp;#123;poster&amp;#125;&amp;#125;&quot; name=&quot;&amp;#123;&amp;#123;name&amp;#125;&amp;#125;&quot; author=&quot;&amp;#123;&amp;#123;author&amp;#125;&amp;#125;&quot; src=&quot;&amp;#123;&amp;#123;src&amp;#125;&amp;#125;&quot; id=&quot;myAudio&quot; controls">
<meta name="keywords" content="小程序">
<meta property="og:type" content="article">
<meta property="og:title" content="小程序-组件-媒体组件">
<meta property="og:url" content="http://yoursite.com/2018/01/16/小程序-组件-媒体组件/index.html">
<meta property="og:site_name" content="尛孟的博客">
<meta property="og:description" content="audio 音频   1234567&amp;lt;audio poster=&quot;&amp;#123;&amp;#123;poster&amp;#125;&amp;#125;&quot; name=&quot;&amp;#123;&amp;#123;name&amp;#125;&amp;#125;&quot; author=&quot;&amp;#123;&amp;#123;author&amp;#125;&amp;#125;&quot; src=&quot;&amp;#123;&amp;#123;src&amp;#125;&amp;#125;&quot; id=&quot;myAudio&quot; controls">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://www.z4a.net/images/2018/01/16/audio.png">
<meta property="og:image" content="http://www.z4a.net/images/2018/01/16/_20180116152934.png">
<meta property="og:image" content="http://www.z4a.net/images/2018/01/16/_20180116153142.png">
<meta property="og:updated_time" content="2018-01-16T08:53:53.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="小程序-组件-媒体组件">
<meta name="twitter:description" content="audio 音频   1234567&amp;lt;audio poster=&quot;&amp;#123;&amp;#123;poster&amp;#125;&amp;#125;&quot; name=&quot;&amp;#123;&amp;#123;name&amp;#125;&amp;#125;&quot; author=&quot;&amp;#123;&amp;#123;author&amp;#125;&amp;#125;&quot; src=&quot;&amp;#123;&amp;#123;src&amp;#125;&amp;#125;&quot; id=&quot;myAudio&quot; controls">
<meta name="twitter:image" content="http://www.z4a.net/images/2018/01/16/audio.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"hide","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: 'ZNJ0RM31SP',
      apiKey: '9fae47ade11c769ab25bba4061522c1d',
      indexName: 'for_meng',
      hits: {"per_page":10},
      labels: {"input_placeholder":"输入关键词进行搜索","hits_empty":" 找不到关于 ”${query}“ 的文章 ","hits_stats":" 共找到${hits} 篇文章,花了${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/01/16/小程序-组件-媒体组件/"/>




<script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
<link href="//cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">


  <title>小程序-组件-媒体组件 | 尛孟的博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">尛孟的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">想法总是无法付诸实践…</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/01/16/小程序-组件-媒体组件/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="尛孟">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="尛孟的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">小程序-组件-媒体组件</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-16T15:15:41+08:00">
                2018-01-16
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/小程序/" itemprop="url" rel="index">
                    <span itemprop="name">小程序</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/小程序/框架学习/" itemprop="url" rel="index">
                    <span itemprop="name">框架学习</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/小程序/框架学习/组件/" itemprop="url" rel="index">
                    <span itemprop="name">组件</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/01/16/小程序-组件-媒体组件/" class="leancloud_visitors" data-flag-title="小程序-组件-媒体组件">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <hr>
<h4 id="audio"><a href="#audio" class="headerlink" title="audio"></a>audio</h4><blockquote>
<p>音频</p>
</blockquote>
<p><img src="http://www.z4a.net/images/2018/01/16/audio.png" alt="音频样式"></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">audio</span> <span class="attr">poster</span>=<span class="string">"&#123;&#123;poster&#125;&#125;"</span> <span class="attr">name</span>=<span class="string">"&#123;&#123;name&#125;&#125;"</span> <span class="attr">author</span>=<span class="string">"&#123;&#123;author&#125;&#125;"</span> <span class="attr">src</span>=<span class="string">"&#123;&#123;src&#125;&#125;"</span> <span class="attr">id</span>=<span class="string">"myAudio"</span> <span class="attr">controls</span> <span class="attr">loop</span>&gt;</span><span class="tag">&lt;/<span class="name">audio</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">&lt;!--  其他组件通过通过createAudioContext(id)获取audio上下文context并进行音频操作 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">"primary"</span> <span class="attr">bindtap</span>=<span class="string">"audioPlay"</span>&gt;</span>播放<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">"primary"</span> <span class="attr">bindtap</span>=<span class="string">"audioPause"</span>&gt;</span>暂停<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">"primary"</span> <span class="attr">bindtap</span>=<span class="string">"audio14"</span>&gt;</span>设置当前播放时间为14秒<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">"primary"</span> <span class="attr">bindtap</span>=<span class="string">"audioStart"</span>&gt;</span>回到开头<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">Page(&#123;</span><br><span class="line">  onReady: <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 使用 wx.createAudioContext 获取 audio 上下文 context</span></span><br><span class="line">    <span class="keyword">this</span>.audioCtx = wx.createAudioContext(<span class="string">'myAudio'</span>)</span><br><span class="line">  &#125;,</span><br><span class="line">  data: &#123;</span><br><span class="line">    poster: <span class="string">'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'</span>,</span><br><span class="line">    name: <span class="string">'此时此刻'</span>,</span><br><span class="line">    author: <span class="string">'许巍'</span>,</span><br><span class="line">    src: <span class="string">'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&amp;uin=346897220&amp;vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&amp;fromtag=46'</span>,</span><br><span class="line">  &#125;,</span><br><span class="line">  audioPlay: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="comment">//用audio上下文控制</span></span><br><span class="line">    <span class="keyword">this</span>.audioCtx.play()</span><br><span class="line">  &#125;,</span><br><span class="line">  audioPause: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="comment">//用audio上下文控制</span></span><br><span class="line">    <span class="keyword">this</span>.audioCtx.pause()</span><br><span class="line">  &#125;,</span><br><span class="line">  audio14: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="comment">//用audio上下文控制</span></span><br><span class="line">    <span class="keyword">this</span>.audioCtx.seek(<span class="number">14</span>)</span><br><span class="line">  &#125;,</span><br><span class="line">  audioStart: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="comment">//用audio上下文控制</span></span><br><span class="line">    <span class="keyword">this</span>.audioCtx.seek(<span class="number">0</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<hr>
<h4 id="image"><a href="#image" class="headerlink" title="image"></a>image</h4><blockquote>
<p>图片</p>
<p>image组件默认宽度300px、高度225px</p>
</blockquote>
<p>图片有13中显示模式,4中是缩放模式,9种是裁剪模式</p>
<p><img src="http://www.z4a.net/images/2018/01/16/_20180116152934.png" alt="图片mode类型"></p>
<hr>
<h4 id="video"><a href="#video" class="headerlink" title="video"></a>video</h4><blockquote>
<p>视频</p>
<blockquote>
<p>不能在<code>scroll-view、swiper、picker-view、movable-view</code>中使用 video 组件。</p>
</blockquote>
</blockquote>
<p><img src="http://www.z4a.net/images/2018/01/16/_20180116153142.png" alt="视频样式"></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">"section tc"</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">video</span> <span class="attr">id</span>=<span class="string">"myVideo"</span> <span class="attr">src</span>=<span class="string">"&#123;&#123;src&#125;&#125;"</span> <span class="attr">danmu-list</span>=<span class="string">"&#123;&#123;danmuList&#125;&#125;"</span> <span class="attr">enable-danmu</span> <span class="attr">danmu-btn</span> <span class="attr">controls</span>&gt;</span><span class="tag">&lt;/<span class="name">video</span>&gt;</span></span><br><span class="line">  </span><br><span class="line">  <span class="comment">&lt;!--  其他组件通过通过wx.createVideoContext(id)获取video上下文context并进行视频操作 --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">"btn-area"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">button</span> <span class="attr">bindtap</span>=<span class="string">"bindButtonTap"</span>&gt;</span>获取视频<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">bindblur</span>=<span class="string">"bindInputBlur"</span>/&gt;</span>    <span class="comment">&lt;!-- 弹幕输入框 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">button</span> <span class="attr">bindtap</span>=<span class="string">"bindSendDanmu"</span>&gt;</span>发送弹幕<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//随机rgb颜色值</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getRandomColor</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> rgb = []</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span> ; i &lt; <span class="number">3</span>; ++i)&#123;</span><br><span class="line">    <span class="keyword">let</span> color = <span class="built_in">Math</span>.floor(<span class="built_in">Math</span>.random() * <span class="number">256</span>).toString(<span class="number">16</span>)</span><br><span class="line">    color = color.length == <span class="number">1</span> ? <span class="string">'0'</span> + color : color</span><br><span class="line">    rgb.push(color)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="string">'#'</span> + rgb.join(<span class="string">''</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">Page(&#123;</span><br><span class="line">  onReady: <span class="function"><span class="keyword">function</span> (<span class="params">res</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 使用 wx.createVideoContext 获取 video 上下文 context</span></span><br><span class="line">    <span class="keyword">this</span>.videoContext = wx.createVideoContext(<span class="string">'myVideo'</span>)</span><br><span class="line">  &#125;,</span><br><span class="line">  inputValue: <span class="string">''</span>,</span><br><span class="line">    data: &#123;</span><br><span class="line">        src: <span class="string">''</span>,</span><br><span class="line">      <span class="comment">//默认的弹幕列表</span></span><br><span class="line">    danmuList: [</span><br><span class="line">      &#123;</span><br><span class="line">        text: <span class="string">'第 1s 出现的弹幕'</span>,</span><br><span class="line">        color: <span class="string">'#ff0000'</span>,</span><br><span class="line">        time: <span class="number">1</span></span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        text: <span class="string">'第 3s 出现的弹幕'</span>,</span><br><span class="line">        color: <span class="string">'#ff00ff'</span>,</span><br><span class="line">        time: <span class="number">3</span></span><br><span class="line">    &#125;]</span><br><span class="line">    &#125;,</span><br><span class="line">  bindInputBlur: <span class="function"><span class="keyword">function</span>(<span class="params">e</span>) </span>&#123;</span><br><span class="line">    <span class="comment">//获取弹幕文本</span></span><br><span class="line">    <span class="keyword">this</span>.inputValue = e.detail.value</span><br><span class="line">  &#125;,</span><br><span class="line">  bindButtonTap: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> that = <span class="keyword">this</span></span><br><span class="line">	<span class="comment">//拍摄视频或从手机相册中选视频，返回视频的临时文件路径</span></span><br><span class="line">    wx.chooseVideo(&#123;</span><br><span class="line">      sourceType: [<span class="string">'album'</span>, <span class="string">'camera'</span>],</span><br><span class="line">      maxDuration: <span class="number">60</span>,</span><br><span class="line">      camera: [<span class="string">'front'</span>,<span class="string">'back'</span>],</span><br><span class="line">      success: <span class="function"><span class="keyword">function</span>(<span class="params">res</span>) </span>&#123;</span><br><span class="line">        that.setData(&#123;</span><br><span class="line">          src: res.tempFilePath</span><br><span class="line">        &#125;)</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;,</span><br><span class="line">  </span><br><span class="line">  bindSendDanmu: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="comment">//调用video上下文实时发送弹幕</span></span><br><span class="line">    <span class="keyword">this</span>.videoContext.sendDanmu(&#123;</span><br><span class="line">      text: <span class="keyword">this</span>.inputValue,</span><br><span class="line">      color: getRandomColor()</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<hr>
<h4 id="camera"><a href="#camera" class="headerlink" title="camera"></a>camera</h4><blockquote>
<p>系统相机</p>
<p>需要用户授权 scope.camera</p>
<blockquote>
<p>不能在 <code>scroll-view、swiper、picker-view、movable-view</code> 中使用 camera 组件。</p>
</blockquote>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">camera</span> <span class="attr">device-position</span>=<span class="string">"back"</span> <span class="attr">flash</span>=<span class="string">"off"</span> <span class="attr">binderror</span>=<span class="string">"error"</span> <span class="attr">style</span>=<span class="string">"width: 100%; height: 300px;"</span>&gt;</span><span class="tag">&lt;/<span class="name">camera</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">"primary"</span> <span class="attr">bindtap</span>=<span class="string">"takePhoto"</span>&gt;</span>拍照<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">view</span>&gt;</span>预览<span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">image</span> <span class="attr">mode</span>=<span class="string">"widthFix"</span> <span class="attr">src</span>=<span class="string">"&#123;&#123;src&#125;&#125;"</span>&gt;</span><span class="tag">&lt;/<span class="name">image</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">Page(&#123;</span><br><span class="line">    takePhoto() &#123;</span><br><span class="line">      <span class="comment">//获取相机上下文 context</span></span><br><span class="line">        <span class="keyword">const</span> ctx = wx.createCameraContext()</span><br><span class="line">        ctx.takePhoto(&#123;</span><br><span class="line">            quality: <span class="string">'high'</span>,</span><br><span class="line">            success: <span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">                <span class="keyword">this</span>.setData(&#123;</span><br><span class="line">                    src: res.tempImagePath</span><br><span class="line">                &#125;)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">    error(e) &#123;</span><br><span class="line">        <span class="built_in">console</span>.log(e.detail)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<hr>
<h4 id="live-player"><a href="#live-player" class="headerlink" title="live-player"></a>live-player</h4><blockquote>
<p>实时音视频播放</p>
<blockquote>
<p>不能在 <code>scroll-view、swiper、picker-view、movable-view</code> 中使用 live-player 组件。</p>
<p>不能直接用,要在小程序后台申请审核</p>
<p>可以通过<code>wx.createLivePlayerContext</code>获取live-player上下文context</p>
</blockquote>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">live-player</span> <span class="attr">src</span>=<span class="string">"https://domain/pull_stream"</span> <span class="attr">mode</span>=<span class="string">"RTC"</span> <span class="attr">autoplay</span> <span class="attr">bindstatechange</span>=<span class="string">"statechange"</span> <span class="attr">binderror</span>=<span class="string">"error"</span> <span class="attr">style</span>=<span class="string">"width: 300px; height: 225px;"</span> /&gt;</span></span><br></pre></td></tr></table></figure>
<hr>
<h4 id="live-pusher"><a href="#live-pusher" class="headerlink" title="live-pusher"></a>live-pusher</h4><blockquote>
<p>实时音视频录制</p>
<blockquote>
<p>不能在 <code>scroll-view、swiper、picker-view、movable-view</code> 中使用 live-pusher 组件。</p>
<p>不能直接用,要在小程序后台申请审核</p>
<p>可以通过<code>wx.createLivePusherContext</code>获取live-player上下文context</p>
</blockquote>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">live-pusher</span> <span class="attr">url</span>=<span class="string">"https://domain/push_stream"</span> <span class="attr">mode</span>=<span class="string">"RTC"</span> <span class="attr">autopush</span> <span class="attr">bindstatechange</span>=<span class="string">"statechange"</span> <span class="attr">style</span>=<span class="string">"width: 300px; height: 225px;"</span> /&gt;</span></span><br></pre></td></tr></table></figure>
<hr>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/小程序/" rel="tag"># 小程序</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/01/15/小程序-组件-表单组件/" rel="next" title="小程序-组件-表单组件">
                <i class="fa fa-chevron-left"></i> 小程序-组件-表单组件
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/01/16/小程序-组件-地图-画布/" rel="prev" title="小程序-组件-地图&画布">
                小程序-组件-地图&画布 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">尛孟</p>
              <p class="site-description motion-element" itemprop="description">与人联系甚少</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">26</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#audio"><span class="nav-number">1.</span> <span class="nav-text">audio</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#image"><span class="nav-number">2.</span> <span class="nav-text">image</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#video"><span class="nav-number">3.</span> <span class="nav-text">video</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#camera"><span class="nav-number">4.</span> <span class="nav-text">camera</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#live-player"><span class="nav-number">5.</span> <span class="nav-text">live-player</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#live-pusher"><span class="nav-number">6.</span> <span class="nav-text">live-pusher</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">尛孟</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.4"></script>



  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("KhsxPkrt4UYiKBnwYFY9zUTN-gzGzoHsz", "a1zezRocQqcmPxlFVdXKrhz9");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
